describe('Move transfer history controller', function(){

    var controller;

    beforeEach(function(){
        var t_appCtrl = App.ApplicationController.create();
        var t_alertCtrl = App.AlertController.create();
        var t_loadingCtrl = App.LoadingController.create();
        App.MoveTransferHistoryController.reopen({

            init:function(){
                this.set('controllers', Em.Object.create({
                    application: t_appCtrl,
                    alert: t_alertCtrl,
                    loading: t_loadingCtrl
                }));
            }
        });

        controller = App.MoveTransferHistoryController.create();
    });

    describe('prepareController', function() {

        it('should get transfer history data and display list', function() {

            var account = null;
            spyOn(App.api_paymentHistory, 'getPaymentHistory').andCallFake(function(account,callback){
                callback();
            });
            controller.prepareController();
            expect(App.api_paymentHistory.getPaymentHistory).toHaveBeenCalled();
        });

        it('should not refresh when coming back from transferDetails screen', function() {

            spyOn(App.RouteHistory, 'previousRoute').andReturn('move.transactionDetails');
            spyOn(App.api_paymentHistory, 'getPaymentHistory').andCallFake(function(account,callback){
                callback();
            });
            controller.prepareController();
            expect(App.api_paymentHistory.getPaymentHistory).not.toHaveBeenCalled();
        });

    });

    describe("paymentHistoryCallback", function(){

        it('return transaction list', function() {

            var objE = {errorCode:'code', errorMessage:'message'};

            spyOn(controller, 'hideLoading');
            spyOn(controller, 'hasError').andReturn(false);
            spyOn(controller, 'buildTransactionListByDate').andReturn([]);

            controller.paymentHistoryCallback({}, objE);

            expect(controller.hideLoading).toHaveBeenCalled();
            expect(controller.hasError).toHaveBeenCalled();
            expect(controller.buildTransactionListByDate).toHaveBeenCalledWith({});
        });
    });
});
